local shizhi = fk.CreateSkill {

  name = "joy__shizhi",

  tags = { Skill.Compulsory, },

}



shizhi:addEffect("filter", {
  name = "joy__shizhi",
  card_filter = function(self, to_select, player, isJudgeEvent)
    return player:hasSkill(shizhi.name) and player.phase ~= Player.NotActive and to_select.name == "jink" and
    (table.contains(player.player_cards[Player.Hand], to_select.id) or isJudgeEvent)
  end,
  view_as = function(self, player,to_select)
    return Fk:cloneCard("slash", to_select.suit, to_select.number)
  end,
})

shizhi:addEffect(fk.Damage, {
  name = "#joy__shizhi_trigger",
  events = {fk.Damage},
  mute = true,
  frequency = Skill.Compulsory,
  can_trigger = function (self, event, target, player, data)
    return player == target and player:hasSkill("joy__shizhi") and data.card
    and table.contains(data.card.skillNames, "joy__shizhi")
  end,
  on_use = function (self, event, target, player, data)
    player:broadcastSkillInvoke("joy__shizhi")
    player.room:notifySkillInvoked(player, "joy__shizhi", "defensive")
    if player:isWounded() then
      player.room:recover { num = 1, skillName = "joy__shizhi", who = player, recoverBy = player}
    end
    if not player.dead then
      player:drawCards(1,shizhi.name)
    end
  end,
})

return shizhi